<template>
    <div id="app">
        <!-- 路由占位符 -->
        <router-view></router-view>
    </div>
</template>

<script>
import router from "@/router/index";
import { initDynamicRoutes } from "@/utils/utils";

export default {
    name: "app",
    data() {
        return {};
    },
    created() {
      let that = this;
        // 获取设备的宽度
        var getPxSize = () => {
            let currentWidth = document.documentElement.clientWidth;
            // console.log(currentWidth);
            let pxSize =
                16 * (currentWidth / 1920) > 32
                    ? 32 + "px"
                    : 16 * (currentWidth / 1920) + "px";
            document.documentElement.style.fontSize = pxSize;
        };
        window.addEventListener("load", getPxSize);
        window.addEventListener("resize", getPxSize);

        this.removeloadingdiv();

        const data = JSON.parse(window.sessionStorage.getItem("RouteData"));

        if (data) {
            const routeArr = initDynamicRoutes(data, []);
            router.addRoutes(routeArr);
        }

        //获取缓存中是否显示历史访问标签，是为了解决当页面刷新时，vuex会重新初始化，showWorkTab为true，而使得在展板页面刷新后访问标签还是显示
        //在页面刷新时将vuex里的信息保存到sessionStorage里
        window.addEventListener("beforeunload", () => {
            window.sessionStorage.setItem(
                "showWorkTab",
                JSON.stringify(this.$store.state.Usersetting.showWorkTab)
            );
        });
        window.addEventListener("unload", () => {
          return;
        });
    },
    methods: {
        removeloadingdiv() {
            setTimeout(() => {
                let loading = document.getElementById("loading");
                if (loading !== null) {
                    document.body.removeChild(loading);
                }
            }, 5);
        },
    },
};
</script>
<style>
#app {
    height: 100vh;
}
/* 去除百度地图底部文字 */
.anchorBL {
    display: none;
}
</style>
